<div class="row wrapper border-bottom white-bg page-heading"
     xmlns="http://www.w3.org/1999/xhtml"
     xmlns:th="http://www.thymeleaf.org">
    <div class="col-lg-9 input-group">
        <h3 th:text="|备份信息 ${dbname.toUpperCase()}|"></h3>
    </div>
    <form role="search" class="navbar-form-custom pull-right" action="javascript:search_user(this);">
        <div class="form-control form-group">
            <input type="text" placeholder="查找..." class="form-control" name="top-search" id="top-search">
        </div>
    </form>
    <!--<form method="get" action="index.html" class="mail-search" action="javascript:search_user(this);">-->
    <!--<div class="input-group">-->
    <!--<input type="text" class="form-control input-sm" name="search" placeholder="查找备份...">-->
    <!--<div class="input-group-btn">-->
    <!--<button type="submit" class="btn btn-sm btn-default">-->
    <!--<i class="fa fa-search"></i> 查找-->
    <!--</button>-->
    <!--</div>-->
    <!--</div>-->
    <!--</form>-->
    <div class="input-group-btn">
        <a href="javascript:void(0);" data-toggle="modal"
           class="btn btn-sm btn-primary"
           th:onclick="'javascript:modalShow(\'\', \'db/'+${dbname}+'/backup\');'"
        >
            <i class="fa fa-plus-circle"></i>&nbsp;创建备份
        </a>
        <a href="javascript:void(0);" data-toggle="modal"
           class="btn btn-sm btn-info"
           th:onclick="'javascript:modalShow(\'\', \'upload/'+${dbname}+'\');'"
        >
            <i class="fa fa-upload"></i>&nbsp;上传备份
        </a>
        <a class="btn btn-sm btn-danger"
           href="javascript:void(0);" th:onclick="'javascript:clearDBLog(\''+${dbname}+'\')'"
        >
            <i class="fa fa-exclamation"></i>&nbsp;清除库日志
        </a>
    </div>

</div>
<div class="wrapper wrapper-content animated fadeInRight" xmlns="http://www.w3.org/1999/xhtml"
     xmlns:th="http://www.thymeleaf.org" id="info-div">
    <div class="row" th:if="${#lists.isEmpty(backups)}">
        <div class="col-lg-4">
            <!-- bg-white,bg-warning,bg-danger -->
            <div class=" contact-box center-version text-uppercase bg-white">
                <a href="javascript:void(0);" data-toggle="modal" th:onclick="'javascript:modalShow(\'\', \'db/'+${dbname}+'/backup\');'">
                    <!-- circle-border m-b-md -->
                    <i class="fa fa-plus-square-o fa-5x"></i>
                    <h3 class="m-b-xs"><strong>未找到备份信息</strong></h3>
                    <div class="font-bold">
                        <small>新建备份</small>
                    </div>
                </a>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-4" th:each="backup : ${backups}">
            <!-- bg-white,bg-warning,bg-danger -->
            <div class=" contact-box center-version text-uppercase bg-white">
                <a href="javascript:void(0);" th:onclick="'javascript:restore(\''+${backup.dvid}+'\')'">
                    <!-- circle-border m-b-md -->
                    <i class="fa fa-database fa-5x"></i>
                    <h3 class="m-b-xs"><strong class="col-lg-12 col-md-12 col-sm-12 col-xs-12 etc"
                                               th:text="${backup.dvname}"></strong></h3><br/>
                    <div>
                        <small th:text="${backup.dvtime}"></small>
                    </div>
                    <address class="m-t-md">
                        <small class="col-lg-12 col-md-12 col-sm-12 col-xs-12 etc" th:text="${backup.dvinfo}"></small>
                    </address>
                </a>
                <div class="contact-box-footer">
                    <a href="javascript:void(0);" th:onclick="'javascript:downloaddv(\''+${backup.dvid}+'\')'"
                       class="btn btn-xs btn-primary">
                        <i class="fa fa-download"></i> 下载 </a>
                    <!--<a href="javascript:void(0);" th:onclick="'javascript:update(\''+${backup.dvid}+'\')'"-->
                       <!--class="btn btn-xs btn-info">-->
                        <!--<i class="fa fa-edit"></i> 修改 </a>-->
                    <a href="javascript:void(0);" th:onclick="'javascript:restore(\''+${backup.dvid}+'\')'"
                       class="btn btn-xs btn-warning">
                        <i class="fa fa-refresh"></i> 还原 </a>
                    <a href="javascript:void(0);"
                       th:onclick="'javascript:deletedv(\''+${backup.dvid}+'\',\''+${backup.dvname}+'\',\''+${backup.dvtime}+'\')'"
                       class="btn btn-xs btn-danger">
                        <i class="fa fa-exclamation-circle"></i> 删除</a>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- iCheck -->
<script src="inspinia/js/plugins/iCheck/icheck.min.js"></script>
<script th:inline="javascript" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
    /*<![CDATA[*/
    var dbname = [[${dbname}]];

    /**
     * 搜索
     */
    function search_user(form) {
        var keyword = $("#top-search").val();
        keyword = encodeURI(keyword);
        keyword = encodeURI(keyword);
        getPage(dbname + '?keyword=' + keyword);
    }

    /**
     * 删除数据库
     */
    function deletedv(vid, dvname, dvtime) {
        $.confirm({
            title: '危险!',
            content: '即将删除数据库备份' + dvname.toUpperCase() + '[' + dvtime + ']的备份文件！确定吗？',
            confirmButton: '确认删除',
            cancelButton: '取消',
            confirmButtonClass: 'btn-danger',
            cancelButtonClass: 'btn-info',
            keyboardEnabled: true,
            confirm: function () {
                showMLoading();
                $.ajax({
                    url: 'db/' + dbname + '/' + vid,
                    type: 'DELETE',
                    timeout: 3000000,
                    dataType: 'json',
                    data: {_method: 'DELETE'},
                    success: function (result) {
                        hideMLoading();
                        if (result.flag) {
                            getPage(dbname);
                            showMessage(2, '删除数据库备份' + dvname.toUpperCase() + '[' + dvtime + ']备份文件成功！', 3);
                        } else {
                            showMessage(3, result.msg, 10);
                        }
                    },
                    failure: function () {
                        hideMLoading();
                        showMessage(3, '暂时无法访问服务器，请稍后重试！', 2);
                    }
                });
            },
            cancel: function () {
                showMessage(0, '用户取消还原数据库操作', 2);
            }
        });
    }

    /**
     * 清除数据库日志文件
     */
    function clearDBLog(dbname) {
        $.confirm({
            title: '警告!',
            content: '即将清除数据库' + dbname.toUpperCase() + '的日志文件，该操作会导致无法找回历史数据',
            confirmButton: '清除日志',
            cancelButton: '取消',
            confirmButtonClass: 'btn-danger',
            cancelButtonClass: 'btn-info',
            keyboardEnabled: true,
            confirm: function () {
                showMLoading();
                $.ajax({
                    url: 'clear/' + dbname,
                    type: 'GET',
                    timeout: 3000000,
                    dataType: 'json',
                    //data: {filename : ui.draggable.get(0).file.name, _method: 'DELETE'},
                    success: function (result) {
                        hideMLoading();
                        if (result.flag) {
//                            $.alert({
//                                title: '提示',
//                                content: '清除数据库' + dbname.toUpperCase() + '日志文件成功！',
//                                confirmButton: '好的',
//                                confirmButtonClass: 'btn-info',
//                                backgroundDismiss: true
//                            });
                            showMessage(2, '清除数据库' + dbname.toUpperCase() + '日志文件成功！', 3);
                        } else {
                            showMessage(3, result.msg, 10);
                        }
                    },
                    failure: function () {
                        hideMLoading();
                        showMessage(3, '暂时无法访问服务器，请稍后重试！', 2);
                    }
                });
            },
            cancel: function () {
                showMessage(0, '用户取消清除数据库日志文件操作', 2);
            }
        });
    }

    /**
     * 下载备份文件
     */
    function downloaddv(vid) {
        var url= 'download/' + dbname + '/' + vid;
        window.location.href = url;
    }

    /**
     * 还原数据库
     */
    function restore(vid) {
        $.confirm({
            title: '警告!',
            content: '即将使用选择的备份文件还原数据库' + dbname.toUpperCase() + '，确定吗？',
            confirmButton: '立即还原',
            cancelButton: '取消',
            confirmButtonClass: 'btn-warning',
            cancelButtonClass: 'btn-info',
            keyboardEnabled: true,
            confirm: function () {
                showMLoading();
                $.ajax({
                    url: 'restore/' + dbname + '/' + vid,
                    type: 'GET',
                    timeout: 3000000,
                    dataType: 'json',
                    //data: {filename : ui.draggable.get(0).file.name, _method: 'DELETE'},
                    success: function (result) {
                        hideMLoading();
                        if (result.flag) {
//                            $.alert({
////                                icon: 'fa fa-spinner fa-spin',
//                                title: '提示',
//                                content: '还原数据库' + dbname.toUpperCase() + '成功！',
//                                confirmButton: '好的',
//                                confirmButtonClass: 'btn-info',
//                                backgroundDismiss: true
//                            });
                            showMessage(1, '还原数据库' + dbname.toUpperCase() + '成功！', 3);
                        } else {
                            showMessage(3, result.msg, 10);
                        }
                    },
                    failure: function () {
                        hideMLoading();
                        showMessage(3, '暂时无法访问服务器，请稍后重试！', 2);
                    }
                });
            },
            cancel: function () {
                showMessage(0, '用户取消还原数据库操作', 2);
            }
        });
    }

    /*]]>*/
</script>